﻿using AutoMapper;
using Product.Common.Command;
using Product.Domain.DomainService;
using Product.Domain.Entity;
using Product.Domain.Repository;
using Product.EntityFrameworkCore;
using Product.EntityFrameworkCore.PO;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Product.Application
{
    public class SpuAppService : ISpuAppService
    {
        private readonly IMapper _mapper;
        private readonly ISpuReposiory _spuReposiory;
        private readonly IUnitOfWork _unitOfWork;
        private readonly SpuDomainService _spuDomainService;

        public SpuAppService(ISpuReposiory spuReposiory,
            SpuDomainService spuDomainService,
            IUnitOfWork unitOfWork,
            IMapper mapper)
        {
            _mapper = mapper;
            _unitOfWork = unitOfWork;
            _spuReposiory = spuReposiory;
            _spuDomainService = spuDomainService;
        }

        public async Task AddSpu(AddSpuCommand cmd)
        {
            var specificationList = _mapper.Map<List<Specification>>(cmd.SpecificationList);
            var skuList = _mapper.Map<List<Sku>>(cmd.SkuList);
            await _spuDomainService.AddSpu(cmd.SpuName, cmd.PicUrl, cmd.CategoryId, cmd.BrandId,
                specificationList, skuList);
            await _unitOfWork.CommitAsync();
        }

    }
}
